package com.bp.hearthealth.pulse.lnapps.ads.topon

import com.anythink.core.api.ATAdInfo
import com.anythink.core.api.ATAdSourceStatusListener
import com.anythink.core.api.AdError
import com.bp.hearthealth.pulse.lnapps.ads.topon.open_ad.listener.ad_source.TopOnAdSourceListener
import com.bp.hearthealth.pulse.lnapps.bp_extension.LogUtil

/**
 * 广告源，插屏广告，TopOn 【广告源】，横幅广告，原生广告新增广告源层级事件回调监听
 */
class ATAdSourceStatusListenerImpl : ATAdSourceStatusListener {


    private var adListener: TopOnAdSourceListener? = null

    fun setSourceStatusListener(sourceListener: TopOnAdSourceListener?) {
        this.adListener = sourceListener
    }


    //竞价广告源开始竞价回调
    //atAdInfo：广告的信息对象，可区分广告平台，主要包含第三方聚合平台的id信息
    override fun onAdSourceBiddingAttempt(adInfo: ATAdInfo) {
        adListener?.onAdSourceBiddingAttempt(adInfo)
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceBiddingAttempt: $adInfo")
    }

    //竞价广告源竞价成功回调
    override fun onAdSourceBiddingFilled(adInfo: ATAdInfo) {
        adListener?.onAdSourceBiddingFilled(adInfo)
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceBiddingFilled: $adInfo")
    }

    //竞价广告源竞价失败回调
    override fun onAdSourceBiddingFail(adInfo: ATAdInfo, adError: AdError) {
        adListener?.onAdSourceBiddingFail(adInfo, adError)
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceBiddingFail Info: $adInfo")
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceBiddingFail error: " + adError.fullErrorInfo)
    }

    //广告源开始加载回调
    override fun onAdSourceAttempt(adInfo: ATAdInfo) {
        adListener?.onAdSourceAttempt(adInfo)
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceAttempt: $adInfo")
    }

    //广告源广告填充回调
    override fun onAdSourceLoadFilled(adInfo: ATAdInfo) {
        adListener?.onAdSourceLoadFilled(adInfo)
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceLoadFilled: $adInfo")
    }

    //广告源加载失败回调
    override fun onAdSourceLoadFail(adInfo: ATAdInfo, adError: AdError) {
        adListener?.onAdSourceLoadFail(adInfo,adError)
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceLoadFail Info: $adInfo")
        LogUtil.iTopOn("TopOn 【广告源】 onAdSourceLoadFail error: " + adError.fullErrorInfo)
    }
}